/**
 * 
 */
package com.taobao.wolfwolf.taobao;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author qinanhg@gmail.com
 * 
 *         创建时间: 2011-10-14 上午12:55:01
 */
public class Reg {
	
	// 颜色
	public static final String COLORKEYWORDS = "灰|蓝|咖啡|红|粉|黄|白|绿|印花|黑|金|银|青玉|藕|紫|裸|槟";
	
	// 扣饰类别
	private static final String PIN = "胸针|发夹|发卡|发叉梳";
	
	// 蝴蝶结层数
	private static final String LAYERS = "单层|双层";
	
	// 蝴蝶结类别
	private static final String TYPES = "鞋花|头饰|衣饰";
	
	// 蝴蝶结材料
	private static final String MATERIAL = "蒙纱|缎带|罗纹";
	
	// 象牙米白色蒙纱 加施华洛世奇钻
	private String regEx1 = "[\u4e00-\u9fa5]*(灰|蓝|咖啡|红|粉|黄|白|绿|印花|黑|金|银|青玉|藕|紫|裸|槟)[\u4e00-\u9fa5]*蒙纱\\x20加施华洛世奇钻";
	
	// 本白色蒙纱 32*120cm
	private String regEx2 = "[\u4e00-\u9fa5]*(灰|蓝|咖啡|红|粉|黄|白|绿|印花|黑|金|银|青玉|藕|紫|裸|槟)[\u4e00-\u9fa5]*\\x20\\w*.\\w*cm";
	
	// 象牙米白 24*36cm胸针款
	private String regEx3 = "[\u4e00-\u9fa5]*(灰|蓝|咖啡|红|粉|黄|白|绿|印花|黑|金|银|青玉|藕|紫|裸|槟)\\x20\\w*.\\w*cm(蒙纱|缎带|鞋花|胸针|发夹|发卡|发叉梳)[款]?";
	
	public String getValue(String str, String regEx) {
		Matcher m = null;
		
		Pattern p = Pattern.compile(regEx);
		m = p.matcher(str);
		
		if(m.find()) {
			return str.substring(m.start(), m.end());
		}
		return null;
	}
	
	public void bb(String str) {
		String color, type, specs, colorRegEx, pinRegEx, specsRegEx = "";
		colorRegEx = "[\u4e00-\u9fa5]*(灰|蓝|咖啡|红|粉|黄|白|绿|印花|黑|金|银|青玉|藕|紫|裸|槟)[色]?";
		pinRegEx = "(" + PIN + ")";
		specsRegEx = "\\w*\\*\\w*cm";
		
		if(str.matches(regEx1)) {
			color = getValue(str, colorRegEx);
			type = getValue(str, pinRegEx);
			System.out.println(color);
			System.out.println(type);
		} else if(str.matches(regEx2)) {
			color = getValue(str, colorRegEx);
			type = getValue(str, pinRegEx);
			specs = getValue(str, specsRegEx);
			System.out.println(color);
			System.out.println(type);
			System.out.println(specs);
		} else if(str.matches(regEx3)) {
			colorRegEx = "[\u4e00-\u9fa5]*(" + COLORKEYWORDS + ")[\u4e00-\u9fa5]*";
			pinRegEx = "(" + PIN + ")";
			specsRegEx = "\\w*.\\w*cm";
			
			color = getValue(str, colorRegEx);
			type = getValue(str, pinRegEx);
			specs = getValue(str, specsRegEx);
			System.out.println(color);
			System.out.println(type);
			System.out.println(specs);
		}
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		new Reg().bb("象牙米白 24*36cm胸针款");
	}

}
